<template>
  <div class="box">
    <div>易司拓</div>
    <div>易司拓</div>
    <div class="flex item item-box">画面和实时数据自动刷新<input class="switch" type="checkbox" v-model="isAutoRefresh"></div>
    <router-link tag="div" to="/setting/alarm" class="item-box bottom-border"><div class="flex item">首页告警类型设置<span class="iconfont icon-fanhui"></span></div></router-link>
    <div class="clg-btn" @touchstart="logout">退出登录</div>
  </div>
</template>

<script>
export default {
  name: 'Setting',
  data () {
    return {
      isAutoRefresh: 0,
      isLoaded: false
    }
  },
  methods: {
    logout () {
      this.$router.push('/login')
    },
    init () {
      this.newProjectDwr.getAutoRefresh(localStorage.userId, res => {
        this.isAutoRefresh = res
      })
    }
  },
  created () {
    this.init()
  },
  watch: {
    isAutoRefresh (val) {
      if (!this.isLoaded) {
        this.isLoaded = true
        return
      }
      var value = val ? 1 : 0
      this.newProjectDwr.savaAutoRefresh(localStorage.userId, value)
    }
  }
}
</script>

<style scoped>
  .bottom-border{
    border-bottom: 1px solid #eee;
  }
  .item-box{
    padding-left: 13px;
    background: #fff;
  }
  .icon-fanhui{
    color: #cacaca;
    transform: rotate(180deg);
    font-size: 17px;
  }
  .item{
    padding-right: 13px;
    justify-content: space-between;
    font-size: 17px;
    height: 45px;
    border-top: 1px solid #eee;
  }
  .box{
  box-sizing: border-box;
    background: #f0eff7;
    padding: 30px 0;
}
  .clg-btn{
    height: 45px;
    background-color: #fff;
    color: #d9534f;
    line-height: 45px;
    text-align: center;
    border-bottom: 1px solid #eee;
    border-top: 1px solid #eee;
    margin: 40px 0;
    font-size: 18px;
  }
  .switch{
    -webkit-appearance: none;
    position: relative;
    width: 52px;
    height: 32px;
    border: 1px solid #DFDFDF;
    outline: 0;
    border-radius: 16px;
    box-sizing: border-box;
    background-color: #DFDFDF;
    transition: background-color 0.1s, border 0.1s;
  }
  .switch:before{
    content: " ";
    position: absolute;
    top: 0;
    left: 0;
    width: 50px;
    height: 30px;
    border-radius: 15px;
    background-color: #FDFDFD;
    transition: transform 0.35s cubic-bezier(0.45, 1, 0.4, 1);
  }
  .switch:after{
    content: " ";
    position: absolute;
    top: 0;
    left: 0;
    width: 30px;
    height: 30px;
    border-radius: 15px;
    background-color: #FFFFFF;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    transition: transform 0.35s cubic-bezier(0.4, 0.4, 0.25, 1.35);
  }
  .switch:checked {
    border-color: #4bd663;
    background-color: #4bd663;
}
  .switch:checked:before{
    transform: scale(0);
  }
  .switch:checked:after{
    transform: translateX(20px);
  }
</style>
